package thread;

public class Demo5 {
    public static void main(String[] args) {
        Object locker = new Object();
        Object locker2 = new Object();
        Thread t1 = new Thread(()->{
           synchronized (locker) {
               System.out.println("t1 线程进入同步代码块");
               try {
                   locker.wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("t1 线程等待结束");
           }
        });

        Thread t2 = new Thread(()-> {
            synchronized (locker) {
                System.out.println("t2 线程进入同步代码块");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t2 线程通知结束");
            }
        });
        Thread t3 = new Thread(()-> {
            synchronized (locker) {
                System.out.println("t3 线程进入同步代码块");
                locker.notify();
                System.out.println("t3 线程通知结束");
            }
        });
        t1.start();
        t2.start();
        t3.start();
    }
}
